package org.intellij.doctree.actions;

import com.intellij.openapi.actionSystem.AnActionEvent;
import org.intellij.doctree.DocTree;
import org.intellij.doctree.DocTreeComponent;
import org.intellij.doctree.node.DocTreeNode;

public class RemoveNode extends TreeEditAction {

    public void actionPerformed(AnActionEvent e) {
        DocTree tree = getTree(e);
        if (tree == null) return;

        DocTreeNode node = tree.getCurrentNode();
        if (node == null || !node.isEditable()) return;

        DocTreeComponent component = getComponent(e);
        if (component == null) return;

        component.removeNode(node);

    }

    public void update(AnActionEvent e) {
        boolean actionEnabled = false;
        DocTree tree = getTree(e);
        if (tree != null) {
            DocTreeNode node = tree.getCurrentNode();
            if (node != null && node.isEditable()) actionEnabled = true;
        }
        e.getPresentation().setEnabled(actionEnabled);
    }

}
